package com.wang.java.basic.framework.map;

import java.util.LinkedHashMap;

/**
 * 基于HashMap引入链表，解决HashMap无序的问题，基于插入顺序排序
 */
public class LinkedHashMapTest {
    public static void main(String[] args) {
        LinkedHashMap<Integer, Integer> linkedHashMap = new LinkedHashMap<>();
        linkedHashMap.put(1, 1);
        linkedHashMap.put(10, 10);
        linkedHashMap.put(9, 9);
        linkedHashMap.put(2, 2);
        linkedHashMap.put(3, 3);
        linkedHashMap.put(8, 8);
        linkedHashMap.put(7, 7);
        linkedHashMap.put(4, 4);
        linkedHashMap.put(5, 6);
        linkedHashMap.put(6, 6);
        // 插入已存在的值
        linkedHashMap.put(10, 9);
        linkedHashMap.forEach((k, v) -> System.out.println(k + ":" + v));
    }
}
